package com.flymobi.admin;

import java.util.List;

import com.flymobi.fw.modules.SM;
import com.flymobi.po.Manager;
import com.flymobi.po.Pindao;
import com.flymobi.util.C;
import com.flymobi.util.WebContext;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Oct 21, 2008 11:16:42 AM
 * @version $Id: ManagerAction.java,v 1.1 2010/04/09 03:27:08 airsou Exp $
 */
public class PindaoAction extends WebAction {
	/*
	 * private String method; private String id;
	 */
	private Pindao pindao;

	
	private String fid;

	/**
	 * @return the fid
	 */
	public String getFid() {
		return fid;
	}

	/**
	 * @param fid the fid to set
	 */
	public void setFid(String fid) {
		this.fid = fid;
	}
	/**
	 * @return the pindao
	 */
	public Pindao getPindao() {
		return pindao;
	}

	/**
	 * @param pindao
	 *            the pindao to set
	 */
	public void setPindao(Pindao pindao) {
		this.pindao = pindao;
	}

	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String webProcess(WebContext context, Manager manager) {
		if ("add".equals(method)) {
			List<Pindao> pindaoList=SM.PindaoService.list();
			context.put("pindaoList", pindaoList);
			return "edit";
		} else if ("edit".equals(method)) {
			Pindao pindao = SM.PindaoService.get(id);
			List<Pindao> pindaoList=SM.PindaoService.list();
			context.put("pindaoList", pindaoList);
			context.put("pindao", pindao);
			return "edit";
		} else if ("delete".equals(method)) {
			SM.PindaoService.delete(id);
			context.put("rmsg", C.TEXT.DELETE_SUCCESS);
			method = "list";
			return this.webProcess(context, manager);
		} else if ("save".equals(method)) {
			if(this.isEmptyId(pindao)){
				pindao.setSyn(false);
			}
			if(pindao.getIdx()==null||pindao.getIdx()==0){
				Long idx=SM.PindaoService.getSeq(pindao.getFatherId());
				pindao.setIdx(idx);
			}
			SM.PindaoService.save(pindao);
			context.put("rmsg", C.TEXT.SAVE_SUCCESS);
			method = "list";
			return this.webProcess(context, manager);
		} else if ("start".equals(method)) {
			Pindao a=SM.PindaoService.get(id);
			a.setShows(true);
			SM.PindaoService.save(a);
			context.put("rmsg", C.TEXT.SAVE_SUCCESS);
			//return "save";
			method = "list";
			return this.webProcess(context, manager);
		}else if ("stop".equals(method)) {
			Pindao a=SM.PindaoService.get(id);
			a.setShows(false);
			SM.PindaoService.save(a);
			context.put("rmsg", C.TEXT.SAVE_SUCCESS);
			//return "save";
			method = "list";
			return this.webProcess(context, manager);
		}else if ("list".equals(method)) {
			List<Pindao> pindaoList = SM.PindaoService.list();
			context.put("pindaoList", pindaoList);
			return "list";
		}else if ("up".equals(method)) {
			SM.PindaoService.updateUp(id);
			context.put("rmsg", C.TEXT.OPERA_SUCCESS);
			method = "list";
			return this.webProcess(context, manager);
		}else if ("down".equals(method)) {
			SM.PindaoService.updateDown(id);
			context.put("rmsg", C.TEXT.SAVE_SUCCESS);
			method = "list";
			return this.webProcess(context, manager);
		} else {
			method = "list";
			return this.webProcess(context, manager);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.camel.admin.WebAction#getSysLog()
	 */
	@Override
	public String getSysLog() {
		String opr = "";

		return opr;
	}
}
